#include <iostream>
#include <unordered_map>
#include <gtest/gtest.h>

static std::unordered_map<int, std::string> map = {{1, "low"}, {2, "medium"}, {3, "high"}};

class MyEnvironment: public testing::Environment
{
public:
    virtual void SetUp() override
    {
        std::cout << "单元测试执行前的初始化" << std::endl;
    }

    virtual void TearDown() override
    {
        std::cout << "单元测试执行后的清理工作" << std::endl;
    }
};

TEST(MyEnvironment, map_find)
{
    std::string grade = "medium";
    auto iter = map.find(2);
    // 若ASSERT_EQ不符合，后面insert语句不会被执行
    ASSERT_EQ(iter->second, grade);
    // 若EXPECT_EQ不符合，后面insert语句正常执行
    //EXPECT_EQ(iter->second, grade);
    map.insert(std::pair<int, std::string>(4, "super"));
    map.insert(std::pair<int, std::string>(5, "top"));
}

TEST(MyEnvironment, map_size)
{
    EXPECT_LE(map.size(), 5);
    ASSERT_GT(map.size(), 3);
}


int main(int argc, char* argv[])
{
    testing::AddGlobalTestEnvironment(new MyEnvironment);
    testing::InitGoogleTest(&argc, argv);
    RUN_ALL_TESTS();

    return 0;
}
